<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
            box-sizing: border-box;
        }

        .box {
            width: 300px;
            height: 200px;
            border: 1px solid #000;
            margin: auto;
        }

        li:hover {
            background-color: skyblue;
        }

        .box>.head {
            display: flex;
            justify-content: space-between;
        }

        .box>.head>li {
            /* width: 35%;
            height: 50px; */
            flex-grow: 1;
            text-align: center;
            cursor: pointer;
        }

        .active {
            background-color: #87ceeb;
        }

        .main {
            position: relative;
        }

        .main>li {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 178px;
            background-color: #87ceeb;
        }

        .mainActive {
            z-index: 999;

        }
    </style>
</head>

<body>
    <div class="box">
        <ul class="head">
            <li class="active">标题一</li>
            <li>标题二</li>
            <li>标题三</li>
        </ul>
        <ul class="main">
            <li class="mainActive">内容一</li>
            <li>内容二</li>
            <li>内容三</li>
        </ul>

    </div>

    <script>
        window.onload = function () {
            let head = document.getElementsByClassName("head");
            let item = head[0].getElementsByTagName("li");

            let main = document.getElementsByClassName("main");
            let main_in = main[0].getElementsByTagName("li");


            for (let i = 0; i < item.length; i++) {
                item[i].inedx = i;
                item[i].onclick = function () {
                    for (let j = 0; j < item.length; j++) {
                        item[j].className = '';
                        main_in[j].style.display = "none";
                    }
                    this.className = "active";
                    this.className = "mainActive";
                    main_in[item[i].inedx].style.display = "block";
                }
            }
        }

    </script>
</body>

</html>